package com.example.minemodule.viewmodel;

import android.app.Application;
import android.text.TextUtils;

import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;

import com.alibaba.android.arouter.launcher.ARouter;
import com.examination.mlib.constants.ARouterConstants;
import com.example.minemodule.entity.ProtocalEntity;
import com.example.minemodule.model.SettingModel;
import com.yilijk.base.base.BaseViewModel;
import com.yilijk.base.network.bean.Resource;

/**
 * Created by SHICHENG
 * on 2021/10/22.
 */
public class SettingViewModel extends BaseViewModel<SettingModel> {


    public SettingViewModel(@NonNull Application application) {
        super(application);
    }

    //获取注册协议文案
    public LiveData<Resource<ProtocalEntity.DataBean>> getProtocalEntity(String documentNo) {
        return getRepository().getProtocalEntity(documentNo);
    }

    //退出登录网络请求
    public LiveData<Resource<String>> getLogoutInfo(){
        return getRepository().getLogoutInfo();
    }


    /**
     * 打开用户注册协议web页面
     * @param dataBean
     */
    public void openProtocalWebPage(ProtocalEntity.DataBean dataBean){
        if (TextUtils.isEmpty(dataBean.getTitle())){
            return;
        }else if (TextUtils.isEmpty(dataBean.getContent())){
            return;
        }else{
            ARouter.getInstance().build(ARouterConstants.MineWebviewActivity)
                    .withString("title", dataBean.getTitle())
                    .withString("url", dataBean.getContent())
                    .withBoolean("ishtml", true)
                    .navigation();
        }
    }

    @Override
    public void createRepository() {
        super.createRepository();
        repository = new SettingModel();
    }
}
